#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int ArraySize = 1e3 + 10;
ll a[ArraySize];
ll dp[ArraySize];
ll rec[ArraySize];
ll Max[ArraySize];
void solve()
{
    int N, K;
    cin >> N >> K;
    int i = 0, j = 0, k = 0;
    ll amax;
    bool positive = 0;
    for (i = 1; i <= N; i++)
    {
        cin >> a[i];
        if (i == 1)
            amax = a[i];
        else if (a[i] > amax)
            amax = a[i];
        if (a[i] > 0 && positive == 0)
            positive = 1;
    }
    dp[1] = a[1];
    rec[1] = 1;
    for (i = 2; i <= N; i++)
    {
        if (dp[i - 1] <= 0)
        {
            dp[i] = a[i];
            rec[i] = i;
        }
        else
        {
            dp[i] = dp[i - 1] + a[i];
            rec[i] = rec[i - 1];
        }
    }
    ll Mmax = 0;
    ll left = 0;
    ll right = 0;
    for (i = 1; i <= N; i++)
    {
        if (dp[i] > Mmax)
        {
            Mmax = dp[i];
            left = rec[i];
            right = i;
        }
    }
    if (positive == 0)
        cout << amax;
    else if (K == 1)
    {
        ll temp;
        if (left > 2 && a[left - 2] > 0)
        {
            if (right <= N - 2 && a[right + 2] > 0)
                temp = a[left - 2] > a[right + 2] ? a[left - 2] : a[right + 2];
            else
                temp = a[left - 2];
        }
        else if (right <= N - 2 && a[right + 2] > 0)
            temp = a[right + 2];
        cout << Mmax + temp;
    }
    else
        cout << Mmax;
}
int main()
{
    solve();
    return 0;
}
